﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using TakeoutMangesBLL;
using Model;

namespace TakeoutMangesWeb
{
    public partial class Showinfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["Usersession"] != null)
            {
                logininfo.Attributes.Add("Style", "display:none");
                showinfo.Attributes.Add("Style", "display:block");
                Models.Usersession us = Session["Usersession"] as Models.Usersession;
                user.InnerHtml = us.UserName;
            }
            else
            {
                logininfo.Attributes.Add("Style", "display:block");
                showinfo.Attributes.Add("Style", "display:none");
            }
            if (!IsPostBack) 
            {
                bindshow();
            }
        }

        public void bindshow() 
        {
            int id=Convert.ToInt32(Request.QueryString["id"]);
            RepeaterGoodsinfo.DataSource = ProductBLL.getProductinfo(id);
            RepeaterGoodsinfo.DataBind();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Redirect("Login.aspx");
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            Session["Usersession"] = null;
            Session.Remove("Usersession");
        }

        protected void RepeaterGoodsinfo_ItemCommand1(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "update")
            {
                Shopcar sp = new Shopcar();
                sp.ProductID =Convert.ToInt32(Request.QueryString["id"]);
                Models.Usersession us = Session["Usersession"] as Models.Usersession;
                int UserID = us.UserID;
                sp.UserID = Convert.ToInt32(UserID);
                sp.Isdelete = 0;
                int r = ShopcarBLL.InsertCar(sp);
                if (r > 0)
                {
                    ClientScript.RegisterStartupScript(GetType(), "", "<Script>alert('添加成功')</Script>");
                }
                else
                {
                    ClientScript.RegisterStartupScript(GetType(), "", "<Script>alert('添加失败')</Script>");
                }
            }
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            Response.Redirect("ShopCar.aspx");
        }
    }
}